<template>
	<view>
		<!-- //添加地址按钮 -->
		<view class="address-choose-box" v-if="Object.keys(address).length==0">
			<button type="primary" size="mini" @click="btnChooseAddress">请选择收货地址</button>
		</view>
		
		<!-- 收货地址信息 -->
		<view class="address-info-box" @click="btnChooseAddress" v-else>
			<!-- 收件人信息 -->
			<view class="row1">
				<view class="row1-left">
					<view class="userName">
						收货人：{{address.userName}}
					</view>
				</view>
				<view class="row1-right">
					<view class="phone">
						电话：{{address.telNumber}}
					</view>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<!-- 收件人地址 -->
			<view class="row2">
				<view class="row2-left">
					收件人地址：
				</view>
				<view class="row2-right">
					{{addstr}}
				</view>
			</view>
		</view>
		<!-- 收货地址底部边框图片 -->
		<image src="/static/cart_border@2x.png" mode="widthFix" class="address-border"></image>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	export default {
		name:"my-address",
		data() {
			return {
			};
		},
		computed:{
			...mapState('my_user',['address']),
			addstr(){
				const {
					provinceName,
					cityName,
					countyName,
					detailInfo
				}=this.address
				
				return provinceName+cityName+countyName+detailInfo
			}
		},
		methods:{
			...mapMutations('my_user',['updateAddress']),
		async	btnChooseAddress(){
			 // 1. 调用小程序提供的 chooseAddress() 方法，即可使用选择收货地址的功能
				const [err,succ]=await uni.chooseAddress()
				// console.log(err,succ);
				if(err==null&&succ.errMsg=='chooseAddress:ok'){
					this.updateAddress(succ)
				}
			}
		}
	}
</script>

<style lang="scss">
.address-choose-box{
	display: flex;
	align-items: center;
	justify-content: center;
	height: 90px;
}
.address-border{
	display: block;
	height: 5px;
	width: 100%;
}
.address-info-box{
	display: flex;
	flex-direction: column;
	justify-content: center;
	font-size: 12px;
	height: 90px;
	padding: 0 5px;
	.row1{
		display: flex;
		justify-content: space-between;
		.row1-right{
			display: flex;
			align-items: center;
			.phone{
				margin-right: 5px;
			}
		}
	}
	.row2{
		display: flex;
		align-items: center;
		margin-top: 10px;
		.row2-left{
			white-space: nowrap;
		}
	}
}
</style>
